package com.hw.blog.common;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;

public class EncryptionAwareDataSource extends BasicDataSource {
	
	private ConfigUtil config;
	
	static Logger logger = Logger.getLogger(EncryptionAwareDataSource.class);

	@Override
    public synchronized void setPassword(String password) {
		//System.out.println("password = " + password + "/" + config.toString());
        try {
			super.setPassword(AES.decrypt(config.getPassKey(), password));
		} catch (Exception e) {
			logger.error(e.toString(), e);
			e.printStackTrace();
		}
    }

	public ConfigUtil getConfig() {
		return config;
	}

	public void setConfig(ConfigUtil config) {
		this.config = config;
	}
	
	/*
	public static void main(String[] args) throws Exception {
		String password = "a4cca5e928f0a72d23d3a44f695fcd46";		
		String aa = AES.decrypt(password); 
		System.out.println("aa = " + aa);
	}
	*/
	
	

}
